/**
* Commands to create independant sets. 
* by Essex Edwards
*    essex@cs.ubc.ca
*/

#include <OGF/quick_start/commands/surface_quick_start_commands.h>
#include <OGF/cells/map/ext_map_editor.h>
//#include <OGF/quick_start/common/skeleton.h>
//#include <OGF/quick_start/common/property_smoother.h>
#include <OGF/cells/map/geometry.h>
#include <queue>
#include <vector>


#include <OGF/quick_start/common/refinement.h>

using namespace std;

namespace OGF {

	void SurfaceDeformCommands::Contract( int number_of_iterations ) 
	{
		for(int i=0 ; i < number_of_iterations ; i++)
		{
			skeleton->extract_iteration(surface());
			surface()->update();
		}

		justContractedMesh = true;
		
	}

	void SurfaceDeformCommands::Simplify ( int vertex_count ) 
	{

		if(justContractedMesh)
			skeleton->initializeSimplifier(surface());
		skeleton->simplify(vertex_count);
		surface()->update();

		justContractedMesh = false;
	}
	
	void SurfaceDeformCommands::Refine() {
		Refinement::Refine(surface(), skeleton->getSkeleton());
		surface()->update();
	}

	void SurfaceDeformCommands::Get_Mass_From_Skeleton()
	{
		skeleton->setFeatureSize();
		surface()->update();
	}

	
	void SurfaceDeformCommands::Bake_Deformation()
	{
		deform.lazy_init(surface());
		deform.bake_deformation();
	}


	void SurfaceDeformCommands::Clear_Boundaries()
	{
		deform.lazy_init(surface());

		FOR_EACH_FACET(Map, surface(), it)
		{
			if( deform.is_on_border( it ) )
				deform.remove_from_border( it );
		}
		surface()->update();
	}

	void SurfaceDeformCommands::Set_Gravity(double G)
	{
		deform.gravity = G*0.0000001;
	}
} 

